/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import BUS.DauSachBUS;
import BUS.NhaXuatBanBUS;
import BUS.TacGiaBUS;
import BUS.TheLoaiBUS;
import Entity.DauSach;
import Entity.NhaXuatBan;
import Entity.TacGia;
import Entity.TheLoai;
import Util.ComboBoxTagModel;
import java.util.ArrayList;
import javax.swing.JOptionPane;

/**
 *
 * @author Dark_Knight
 */
public class formThemDauSach extends javax.swing.JPanel {

    private TacGiaBUS       tacGiaBUS;
    private NhaXuatBanBUS   nhaXuatBanBUS;
    private TheLoaiBUS      theLoaiBUS;
    private DauSachBUS      dauSachBUS;
    
    private ComboBoxTagModel cmbTacGiaModels = null;
    private ComboBoxTagModel cmbNXBModels = null;
    private ComboBoxTagModel cmbTheLoaiModels = null;
    
    /**
     * Creates new form formThemDauSach
     */
    public formThemDauSach() {
        initComponents();        
        tacGiaBUS = new BUS.TacGiaImpl();
        nhaXuatBanBUS = new BUS.NhaXuatBanImpl();
        theLoaiBUS = new BUS.TheLoaiImpl();
        dauSachBUS = new BUS.DauSachImpl();

        txtSDT.setTransferHandler(null);

        txtStatus.setText("");
        loadData();
    }
    
    protected void loadData() {        
       loadTacGia();
       loadNhaXuatBan();
       loadTheLoai();
    }
    
    protected void loadTacGia() {
        ArrayList list;  
        cmbTacGiaModels = new ComboBoxTagModel();
                
        // get list TacGia
        list = tacGiaBUS.getTacGia();  
        for(int i = 0; i < list.size(); i++) {
            TacGia tg = (TacGia)list.get(i);
            cmbTacGiaModels.addElement(tg.getTenTacGia(), tg.getMaTacGia());            
        }
        cmbTacGia.setModel(cmbTacGiaModels);      
    }
    
    protected void loadNhaXuatBan() {
        ArrayList list;  
        cmbNXBModels = new ComboBoxTagModel();
        
        // get list NhaXuatBan        
        list = nhaXuatBanBUS.getAll();  
        for(int i = 0; i < list.size(); i++) {
            NhaXuatBan tg = (NhaXuatBan)list.get(i);
            cmbNXBModels.addElement(tg.getTenNXB(), tg.getMaNXB());
        }
        cmbNXB.setModel(cmbNXBModels);
    }

    protected void loadTheLoai() {
        ArrayList list;
        cmbTheLoaiModels = new ComboBoxTagModel();
        
        // get list TheLoai
        list = theLoaiBUS.getAll();
        for(int i=0; i < list.size(); i++) {
            TheLoai tg = (TheLoai) list.get(i);
            cmbTheLoaiModels.addElement(tg.getTenTheLoai(), tg.getMaTheLoai());
        }
        cmbTheLoai.setModel(cmbTheLoaiModels);
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel9 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        txtNewTacGia = new javax.swing.JTextField();
        btnThemTacGia = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        txtNewNXB = new javax.swing.JTextField();
        btnThemNXB = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        txtDiaChi = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        txtSDT = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        txtEmail = new javax.swing.JTextField();
        txtStatus = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        txtNewTheLoai = new javax.swing.JTextField();
        btnThemTheLoai = new javax.swing.JButton();
        jLabel12 = new javax.swing.JLabel();
        txtMoTa = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        cmbNXB = new javax.swing.JComboBox();
        btnThemDS = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        txtTenSach = new javax.swing.JTextField();
        cmbTacGia = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        cmbTheLoai = new javax.swing.JComboBox();
        btnNhapLai = new javax.swing.JButton();

        jLabel9.setFont(new java.awt.Font("Arial", 1, 36));
        jLabel9.setText("THÊM ĐẦU SÁCH");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Thêm Tác Giả"));

        jLabel4.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel4.setText("Tên Tác Giả :");

        txtNewTacGia.setFont(new java.awt.Font("Arial", 0, 12));

        btnThemTacGia.setFont(new java.awt.Font("Arial", 0, 12));
        btnThemTacGia.setText("Thêm");
        btnThemTacGia.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnThemTacGiaMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(jLabel4)
                .addGap(42, 42, 42)
                .addComponent(txtNewTacGia, javax.swing.GroupLayout.PREFERRED_SIZE, 282, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnThemTacGia)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtNewTacGia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnThemTacGia))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Thêm Nhà Xuất Bản"));

        jLabel5.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel5.setText("Tên Nhà Xuất Bản :");

        txtNewNXB.setFont(new java.awt.Font("Arial", 0, 12));

        btnThemNXB.setFont(new java.awt.Font("Arial", 0, 12));
        btnThemNXB.setText("Thêm");
        btnThemNXB.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnThemNXBMouseClicked(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel6.setText("Địa Chỉ :");

        txtDiaChi.setFont(new java.awt.Font("Arial", 0, 12));

        jLabel7.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel7.setText("SĐT :");

        txtSDT.setFont(new java.awt.Font("Arial", 0, 12));
        txtSDT.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtSDTKeyTyped(evt);
            }
        });

        jLabel8.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel8.setText("Email :");

        txtEmail.setFont(new java.awt.Font("Arial", 0, 12));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 281, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(txtSDT, javax.swing.GroupLayout.PREFERRED_SIZE, 281, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(txtDiaChi, javax.swing.GroupLayout.PREFERRED_SIZE, 281, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtNewNXB, javax.swing.GroupLayout.PREFERRED_SIZE, 281, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addComponent(btnThemNXB)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtNewNXB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnThemNXB))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txtDiaChi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(txtSDT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        txtStatus.setFont(new java.awt.Font("Arial", 3, 14));
        txtStatus.setForeground(new java.awt.Color(255, 0, 0));
        txtStatus.setText("status");

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Thêm Thể Loại"));

        jLabel11.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel11.setText("Tên Thể Loại :");

        txtNewTheLoai.setFont(new java.awt.Font("Arial", 0, 12));

        btnThemTheLoai.setFont(new java.awt.Font("Arial", 0, 12));
        btnThemTheLoai.setText("Thêm");
        btnThemTheLoai.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnThemTheLoaiMouseClicked(evt);
            }
        });

        jLabel12.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel12.setText("Mô tả :");

        txtMoTa.setFont(new java.awt.Font("Arial", 0, 12));

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel11)
                    .addComponent(jLabel12))
                .addGap(34, 34, 34)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(txtNewTheLoai, javax.swing.GroupLayout.PREFERRED_SIZE, 282, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnThemTheLoai))
                    .addComponent(txtMoTa, javax.swing.GroupLayout.PREFERRED_SIZE, 282, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(12, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(txtNewTheLoai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnThemTheLoai))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(txtMoTa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Thêm Đầu Sách"));

        cmbNXB.setEditable(true);
        cmbNXB.setFont(new java.awt.Font("Arial", 0, 12));

        btnThemDS.setFont(new java.awt.Font("Arial", 0, 12));
        btnThemDS.setText("Thêm");
        btnThemDS.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnThemDSMouseClicked(evt);
            }
        });
        btnThemDS.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnThemDSActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel2.setText("Tác Giả :");

        jLabel10.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel10.setText("Thể Loại :");

        txtTenSach.setFont(new java.awt.Font("Arial", 0, 12));

        cmbTacGia.setEditable(true);
        cmbTacGia.setFont(new java.awt.Font("Arial", 0, 12));

        jLabel3.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel3.setText("Nhà Xuất Bản :");

        jLabel1.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel1.setText("Tên Sách :");

        cmbTheLoai.setEditable(true);
        cmbTheLoai.setFont(new java.awt.Font("Arial", 0, 12));

        btnNhapLai.setFont(new java.awt.Font("Arial", 0, 12));
        btnNhapLai.setText("Nhập lại");
        btnNhapLai.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnNhapLaiMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1)
                    .addComponent(jLabel10))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(cmbTheLoai, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(txtTenSach, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(btnThemDS, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnNhapLai))
                    .addComponent(cmbTacGia, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(cmbNXB, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtTenSach, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(17, 17, 17)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(cmbTheLoai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(cmbTacGia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(cmbNXB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnNhapLai)
                    .addComponent(btnThemDS))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(txtStatus))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addGap(30, 30, 30)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(30, 30, 30))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addComponent(jLabel9)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(22, 22, 22)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(txtStatus)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnNhapLaiMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnNhapLaiMouseClicked
        txtTenSach.setText("");        
    }//GEN-LAST:event_btnNhapLaiMouseClicked

    private void btnThemDSMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnThemDSMouseClicked
        int MaTG = (Integer) cmbTacGiaModels.getTagItem(cmbTacGia.getSelectedIndex());
        int MaNXB = (Integer) cmbNXBModels.getTagItem(cmbNXB.getSelectedIndex());
        int MaTheLoai = (Integer) cmbTheLoaiModels.getTagItem(cmbTheLoai.getSelectedIndex());
        
        DauSach data = new DauSach(0, MaTG, MaNXB, MaTheLoai, txtTenSach.getText());
        
        if (dauSachBUS.add(data)) {
            txtTenSach.setText("");
            txtStatus.setText("Đã cập nhật Đầu Sách");
        } else {
            JOptionPane.showMessageDialog(this, "Thêm Đầu Sách Không Thành Công");
        }
    }//GEN-LAST:event_btnThemDSMouseClicked

    private void btnThemTacGiaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnThemTacGiaMouseClicked
        TacGia data = new TacGia();
        data.setTenTacGia(txtNewTacGia.getText());
        if (tacGiaBUS.add(data)) {
            loadTacGia();
            txtNewTacGia.setText("");
            txtStatus.setText("Đã cập nhật Tác Giả");
        } else {
            JOptionPane.showMessageDialog(this, "Thêm Tác Giả Không Thành Công");
        }
    }//GEN-LAST:event_btnThemTacGiaMouseClicked

    private void btnThemNXBMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnThemNXBMouseClicked
        NhaXuatBan data = new NhaXuatBan(0, txtNewNXB.getText(),txtDiaChi.getText(), 
                txtSDT.getText(), txtEmail.getText());
        if (nhaXuatBanBUS.add(data)) {
            loadNhaXuatBan();
            
            txtNewNXB.setText("");
            txtDiaChi.setText("");
            txtSDT.setText("");
            txtEmail.setText("");
            
            txtStatus.setText("Đã cập nhập Nhà Xuất Bản");
        } else {
            JOptionPane.showMessageDialog(this, "Thêm NXB Không Thành Công");
        }
    }//GEN-LAST:event_btnThemNXBMouseClicked

    private void btnThemDSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnThemDSActionPerformed
        
    }//GEN-LAST:event_btnThemDSActionPerformed

    private void btnThemTheLoaiMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnThemTheLoaiMouseClicked
        TheLoai data = new TheLoai(0, txtNewTheLoai.getText(), txtMoTa.getText());
        if (theLoaiBUS.add(data)) {
            loadTheLoai();
            
            txtNewTheLoai.setText("");
            txtMoTa.setText("");
            
            txtStatus.setText("Đã cập nhật Thể Loại");
        } else {
            JOptionPane.showMessageDialog(this, "Thêm Thể Loại Không Thành Công");
        }
    }//GEN-LAST:event_btnThemTheLoaiMouseClicked

    private void txtSDTKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtSDTKeyTyped
        Util.InstanceData.check(evt);
    }//GEN-LAST:event_txtSDTKeyTyped

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnNhapLai;
    private javax.swing.JButton btnThemDS;
    private javax.swing.JButton btnThemNXB;
    private javax.swing.JButton btnThemTacGia;
    private javax.swing.JButton btnThemTheLoai;
    private javax.swing.JComboBox cmbNXB;
    private javax.swing.JComboBox cmbTacGia;
    private javax.swing.JComboBox cmbTheLoai;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JTextField txtDiaChi;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtMoTa;
    private javax.swing.JTextField txtNewNXB;
    private javax.swing.JTextField txtNewTacGia;
    private javax.swing.JTextField txtNewTheLoai;
    private javax.swing.JTextField txtSDT;
    private javax.swing.JLabel txtStatus;
    private javax.swing.JTextField txtTenSach;
    // End of variables declaration//GEN-END:variables
}
